﻿using DevExpress.Utils.MVVM;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DotNetExtensions.AspNet.DevExpress.Behaviors
{
    public class ControlCBehavior : EventTriggerBase<System.Windows.Forms.KeyEventArgs>
    {
        public ControlCBehavior()
            : base("KeyDown")
        {
        }
        protected override void OnEvent()
        {
            if (Args.Control && Args.KeyCode == System.Windows.Forms.Keys.C)
            {
                var cbService = this.GetService<Services.IClipboardService>();
                GridView View = Source as GridView;
                if (View.GetRowCellValue(View.FocusedRowHandle, View.FocusedColumn) != null && View.GetRowCellValue(View.FocusedRowHandle, View.FocusedColumn).ToString() != string.Empty)
                    cbService.SetText(View.GetRowCellValue(View.FocusedRowHandle, View.FocusedColumn).ToString());
                else
                    XtraMessageBox.Show("The value in the selected cell is null or empty!");
                Args.Handled = true;
            }
        }
    }
}
